﻿using UnityEngine;
public static class Collision2DExtensions
{
    public static float GetImpactForce(this Collision2D collision)
    {
        float impulse = 0F;

        foreach (ContactPoint2D point in collision.contacts)
        {
            impulse += point.normalImpulse;
        }

        return impulse / Time.fixedDeltaTime;
    }
    public static Vector2 GetNormal(this Collision2D collision)
    {
        Vector2 normal = Vector2.zero;

        foreach (ContactPoint2D point in collision.contacts)
        {
            normal += point.normal;
        }

        return normal /(1f*collision.contacts.Length);
    }
    public static Vector2 GetCotactPos(this Collision2D collision)
    {
        Vector2 pos = Vector2.zero;
        foreach (ContactPoint2D point in collision.contacts)
        {
            pos += point.point;
       //     Debug.Log(point.point);
        }
        return pos / (1f * collision.contacts.Length);
    }
}